<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='保存文章',active='publish'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<link th:href="@{/backadmin/plugins/tagsinput/jquery.tagsinput.css}" rel="stylesheet"/>
<link th:href="@{/backadmin/plugins/select2.dist.css/select2-bootstrap.css}" rel="stylesheet"/>
<link th:href="@{/backadmin/plugins/toggles/toggles.css}" rel="stylesheet"/>

<link th:href="@{/backadmin/css/multi-select.css}" rel="stylesheet"/>
<link th:href="@{/backadmin/css/select2.min.css}" rel="stylesheet"/>
<link th:href="@{/backadmin/plugins/md/css/style.css}" rel="stylesheet"/>

<style>
    #tags_tagsinput {
        background-color: #fafafa;
        border: 1px solid #eeeeee;
    }

    #tags_addTag input {
        width: 100%;
    }

    #tags_addTag {
        margin-top: -5px;
    }
</style>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">
                            <th:block th:if="${null != contents}">
                                编辑文章
                            </th:block>
                            <th:block th:unless="${null != contents}">
                                发布文章
                            </th:block>
                        </h4>
                    </div>
                    <div class="col-md-12">
                        <form id="articleForm" role="form" novalidate="novalidate">
                            <input type="hidden" name="categories" id="categories"/>
                            <input type="hidden" name="tags" id="tags"/>
                            <input type="hidden" name="cid" th:value="${contents!=null and contents.cid!=null}?${contents.cid}: ''" id="cid"/>
                            <input type="hidden" name="status" th:value="${contents!=null and contents.status !=null}?${contents.status}: 'publish'" id="status"/>
                            <input type="hidden" name="allowComment" th:value="${contents!=null and contents.allowComment !=null}?${contents.allowComment}: 1" id="allow_comment"/>
                            <input type="hidden" name="allowPing" th:value="${contents!=null and contents.allowPing !=null}?${contents.allowPing}: 1" id="allow_ping"/>
                            <input type="hidden" name="allowFeed" th:value="${contents!=null and contents.allowFeed !=null}?${contents.allowFeed}: 1" id="allow_feed"/>
                            <input type="hidden" name="content" id="content-editor"/>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input type="text" class="form-control" placeholder="请输入文章标题（必须）" name="title"
                                       required="required"
                                       aria-required="true"
                                       th:value="${contents!=null and contents.title!=null }?${contents.title}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 0 0 10px;">
                                <input type="text" class="form-control"
                                       placeholder="自定义访问路径，如：my-first-article  默认为文章id" name="slug"
                                       th:value="${contents!=null and contents.slug !=null}?${contents.slug}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <select id="multiple-sel-tags" class="select2 form-control" multiple="multiple"
                                        data-placeholder="请选择文章标签...">
                                    <!--<th:block th:if="${null == categories}">
                                        <option value="默认分类" selected="selected">默认分类</option>
                                    </th:block>-->
                                    <th:block th:unless="${null == tags}">
                                        <th:block th:each="c : ${tags}">
                                            <option th:value="${c.name}" th:text="${c.name}"
                                                    th:selected="${null !=contents and adminCommons.exist_cat(c, contents.tags)}?true:false"></option>
                                        </th:block>
                                    </th:block>
                                </select>

                            </div>

                            <div class="form-group col-md-6">
                                <select id="multiple-sel" class="select2 form-control" multiple="multiple"
                                        data-placeholder="请选择文章分类...">
                                    <th:block th:if="${null == categories}">
                                        <option value="默认分类" selected="selected">默认分类</option>
                                    </th:block>
                                    <th:block th:unless="${null == categories}">
                                        <th:block th:each="c : ${categories}">
                                            <option th:value="${c.name}" th:text="${c.name}"
                                                    th:selected="${null !=contents and adminCommons.exist_cat(c, contents.categories)}?true:false"></option>
                                        </th:block>
                                    </th:block>
                                </select>
                            </div>
                            <div class="clearfix"></div>
                            <div class="form-group">
                                <textarea style="height: 450px" autocomplete="off" id="text" name="text"
                                          class="markdown-textarea"
                                          th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">开启评论</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowComment!=null }?'toggle toggle-success allow-'+${contents.allowComment}:'toggle toggle-success allow-true'"
                                         onclick="allow_comment(this);"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">允许Ping</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowPing !=null}?'toggle toggle-success allow-'+${contents.allowPing}:'toggle toggle-success allow-true'"
                                         onclick="allow_ping(this);"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">允许订阅</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and  contents.allowFeed !=null}?'toggle toggle-success allow-'+${contents.allowFeed}: 'toggle toggle-success allow-true'"
                                         onclick="allow_feed(this);"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4"></div>

                            <!-- dropone -->
                            <div class="filed">
                                <label></label>
                                <div id="file" class="dropzone"></div>
                            </div>
                            <label></label>
                            <!-- dropone -->

                            <div class="clearfix"></div>

                            <div class="text-right">
                                <a class="btn btn-default waves-effect waves-light" th:href="@{/admin/article}">返回列表</a>
                                <button type="button" class="btn btn-primary waves-effect waves-light"
                                        onclick="subArticle('publish');">
                                    保存文章
                                </button>
                                <button type="button" class="btn btn-warning waves-effect waves-light"
                                        onclick="subArticle('draft');">
                                    存为草稿
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>

<script th:src="@{/backadmin/plugins/tagsinput/jquery.tagsinput.min.js}"></script>
<script th:src="@{/backadmin/plugins/jquery-multi-select/jquery.quicksearch.js}"></script>

<script th:src="@{/backadmin/plugins/md/js/jquery.scrollto.js}"></script>
<script th:src="@{/backadmin/plugins/md/js/pagedown.js}"></script>
<script th:src="@{/backadmin/plugins/md/js/pagedown-extra.js}"></script>
<script th:src="@{/backadmin/plugins/md/js/diff.js}"></script>
<script th:src="@{/backadmin/plugins/md/js/md.js}"></script>

<script th:src="@{/backadmin/js/jquery.multi-select.min.js}"></script>
<script th:src="@{/backadmin/js/select2.min.js}"></script>
<script th:src="@{/backadmin/js/toggles.min.js}"></script>
<script th:src="@{/backadmin/js/article.js}"></script>

<link th:href="@{/backadmin/dropzonejs/dropzone.min.css}" rel="stylesheet"/>
<script th:src="@{/backadmin/dropzonejs/dropzone.min.js}"></script>


<script type="text/javascript">
    Dropzone.autoDiscover = false;
    var dropz = new Dropzone("#file", {
        url: "uploadImage", //必须填写
        method: "post",  //也可用put
        paramName: "filedata", //默认为file
        maxFiles: 10,//一次性上传的文件数量上限
        maxFilesize: 20, //MB
        acceptedFiles: ".jpg,.gif,.png", //上传的类型
        previewsContainer: "#file", //显示的容器
        parallelUploads: 3,
        addRemoveLinks: true, // 开启删除的按钮
        dictMaxFilesExceeded: "您最多只能上传10个文件！",
        dictResponseError: '文件上传失败!',
        dictInvalidFileType: "你不能上传该类型文件,文件类型只能是*.jpg,*.gif,*.png。",
        dictFallbackMessage: "浏览器不受支持",
        dictFileTooBig: "文件过大上传文件最大支持.",
        dictRemoveFile: "Remove",
        dictDefaultMessage: "点击空白处上传图片(支持多图、拖拽)",
        //previewTemplate: document.querySelector('#preview-template').innerHTML,//设置显示模板
        init: function () {
            this.on("success", function (file,serverResponse) {
                // 替换文件名字
                $(file.previewElement).find('[data-dz-name]').html(serverResponse.fileUrl);
            });
            this.on("addedfile", function (file) {

            });
            this.on("removedfile", function (file) {
                var path = $(file.previewElement).find('[data-dz-name]').html();

                $.ajax({
                    type: 'post',
                    url: 'deletePicture',
                    data: {path: path},
                    async: false,
                    dataType: 'json',
                    success: function (result) {
                        if (result && result.success) {
                        } else {
                            alert("删除失败");
                        }
                    }
                });

            });
        }
    });

</script>

</body>
</html>